package com.design.mode.responsibility;

import java.util.concurrent.atomic.LongAdder;

/**
 * @author 宫静雨
 * @version 1.0
 * @since 2023-04-06 14:33:04
 */
public abstract class Approved {

    protected Approved approved;
    private final String name;
    protected LongAdder next = new LongAdder();

    public Approved(String name) {
        this.name = name;
    }

    public void setApproved(Approved approved) {
        this.approved = approved;
    }

    public String getName() {
        return name;
    }

    public abstract void process(Request request);

    protected void increment() {
        next.increment();
        if (next.sum() >= 5) {
            throw new IllegalArgumentException("链条过长: " + next.sum());
        } else {
            next.increment();
        }
    }
}
